<template>
<div class="mainDiv" style="padding: 10px;box-sizing: border-box;">
	<div class="rowHead">
	<el-button icon="h-shuaxin1" class="buttonLeft" type="primary" @click="searchList">刷新列表</el-button>
			<el-input
				class="searchArea"
				v-model="page.search"
				placeholder="请输入厂商名称或描述"
				@keyup.enter.native="searchList">
				<i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="searchList"></i>
				</el-input>
			
		</div>
		<el-table :data="list" :stripe="true" @row-click="danji" @row-dblclick="dblclick" height="100%">
			<el-table-column prop="id" label="厂商ID"></el-table-column>
			<el-table-column prop="name" label="厂商名称"></el-table-column>
			<el-table-column prop="shopid" label="所属">
				<template slot-scope="scope">
					<el-tag type="success" sizi="mini" v-if="scope.row.shopid == 0">机构</el-tag>
					<el-tag type="info" sizi="mini" v-else>自营</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="remarks" label="厂商描述" :show-overflow-tooltip="true"></el-table-column>
			<el-table-column prop="addtime" label="添加时间">
				<template slot-scope="scope">
					{{scope.row.addtime|dateTime}}
				</template>
			</el-table-column>
			<el-table-column label="选择">
				<template slot-scope="scope">
					<el-switch
						v-model="scope.row.selected"
						on-text="是"
						off-text="否">
					</el-switch>
				</template>
			</el-table-column>
		</el-table>
		<div style="display: flex;justify-content: space-between; padding:10px 0 0 0">
			<el-pagination
				@current-change="currentChange"
				:current-page="page.pages"
				:page-size="page.limits"
				layout="total, prev, pager, next"
				:total="total">
			</el-pagination>
			<div class="block mt right">
				<el-button icon="upload2" type="success" size="mini" @click="submit">确定选择</el-button>
				<el-button icon="close" type="danger" size="mini" @click="close">取消关闭</el-button>
			</div>
		</div>
		
</div>
</template>

<script>
import C from '@/common/common.js'
import Factory from '@/service/shop/factory.js'

export default {
  name: 'openFactoryList',
  data () {
    return {
      list: [],
      total: 0,
      page: {
        pages: 1,
        limits: 15,
        search: ''
      },
      select: {}
    }
  },
  methods: {
    danji: function (row, event) {
      event.preventDefault()
      this.list.forEach((col) => {
        col.selected = false
      })
      row.selected = true
      this.select = row
    },
    dblclick: function (row, event) {
      event.preventDefault()
      C.closeBrowserWindow(row)
    },
    submit: function () {
      if (!this.select.id) {
        C.error('请选择厂商')
        return false
      }
      C.closeBrowserWindow(this.select)
    },
    close: function () {
      C.closewin()
    },
    searchList: function () {
      this.updateList()
    },
    currentChange: function (val) {
      this.page.pages = val
      this.updateList()
    },
    updateList: async function () {
      let data = await Factory.getAllFactoryList(this.page)
      if (data) {
        this.total = data.count
        data.data.forEach((row) => {
          row.selected = false
        })
        this.list = data.data
      }
    }
  },
  mounted: function () {
    this.updateList()
  }
}
</script>

<style>
	tr{
		cursor: pointer;
	}
</style>